{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="think-box-shadow">

    <table class="layui-table margin-top-10" lay-filter="mxTable" lay-skin="line" id="mxTable">
    </table>
    <script type="text/html" id="toolbarDemo">
        {if isset($info.status)&&$info.status==1}
        <button class="layui-btn layui-btn-sm layui-btn-normal " lay-event="subt" type="button">确认</button>
        {/if}
    </script>
</div>
{/block}
{block name="script"}
<!-- /主体 -->
<script>
    const moduleInit = ['tool'];
    function gouguInit() {
        var form =layui.form;

        var treeTable = layui.table;
        // $.extend(treeTable, {config: {checkName: 'checked'}});
        var tableIns = treeTable.render({
            elem: '#mxTable'
            , url: "{:url('api/getContractList')}?type=1&isOver=1&punterId={$purveyorId}"
            , method: 'post'
            , toolbar: '#toolbarDemo',
            defaultToolbar: []
            , cellMinWidth: 80
            , cols: [[
                {type: 'checkbox', fixed: 'left'},
                {fixed: 'left', field: 'id', title: 'ID', unresize: true, hide: true}
                // ,{field: 'id', width: 80, title: 'ID号', align: 'center'}
                , {field: 'orderNum', title: '合同号'}
                , {field: 'unPay', title: '未付金额'}
                , {field: 'money', title: '到款金额',edit:"number"}
            ]],
            parseData:function (data) {
                let tableData=[];
                data.data.forEach(function (item) {
                    item.money=item.unPay;
                    tableData.push(item)
                })
                data.data=tableData;
                return data;
            }
            , page: true
        });
        // form.on('submit(webform)', function (data) {
        //     tableIns.reload({
        //         where: data.field,
        //         page: {
        //             curr: 1
        //         }
        //     });
        //     return false;
        // });
        treeTable.on('toolbar(mxTable)', function (obj) {
            var checkStatus = treeTable.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch (obj.event) {
                case 'add':
                    break;
                case 'subt':
                    var data = checkStatus.data;
                    var param = []
                    let islert=0;
                    let isnullMoney=0;
                    console.log('dddd',data)
                    data.forEach(function (value, index) {
                        if (parseFloat(value.unPay)<parseFloat(value.money)){
                            islert=1;
                        }
                        if (value.money==''||parseFloat(value.money)<=0){
                            isnullMoney=1;
                        }
                        if (value.money!=''&&parseFloat(value.money)>0){
                            param.push(value)
                        }
                    })
                    if (islert!=0){
                        layer.msg('到款金额大于未付金额');
                        return;
                    }
                    if (isnullMoney>0){
                        layer.msg('请填写金额');
                        return;
                    }
                    httpRequest("{:url('')}?receiptId={$receiptId}",{data:param},function (res) {
                        if (res.code==0){
                            setTimeout(function () {
                                parent.parent.location.reload();
                            },1000)

                        }
                    })

                    break;
                case 'import':

                    break;

            }
            ;
        })

    }

    function saveMx(data) {
        parent.saveAddMx(data)

    }
</script>
<!-- 脚本 -->
{/block}


